home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / CBASE102.ARJ / CBDDLPL.L < prev    next >
Text File  |  1991-09-23  |  4KB  |  189 lines

  1. /*    Copyright (c) 1989 Citadel    */
  2. /*       All Rights Reserved        */
  3.  
  4. /* definition section --------------------------------------------------------*/
  5. %{
  6. /* #ident    "@(#)cbddlpl.l    1.6 - 91/09/23" */
  7.  
  8. #include <ansi.h>
  9.  
  10. /* ansi headers */
  11. #ifdef AC_STDLIB
  12. #include <stdlib.h>
  13. #endif
  14.  
  15. /* local headers */
  16. #include "basstr.h"
  17. #include "cbddlp.h"
  18. #ifdef DOS            /* note:  The DOS patches are for GNU flex */
  19. #include "y_tab.h"
  20.  
  21. #undef ECHO            /* disable lex output */
  22. #define ECHO
  23. int yylineno = 0;
  24. #else
  25. #include "y.tab.h"
  26.  
  27. #undef output            /* disable lex output */
  28. #define output(c)
  29. #endif
  30.  
  31. /* function declarations */
  32. #ifdef AC_PROTO
  33. int skipcomment(void);
  34. #else
  35. int skipcomment();
  36. #endif
  37.  
  38. #ifdef DEBUG
  39. #define DBPRINT {                            \
  40.     fprintf(stderr, "%s[%d]: \"%s\" found at line %d.\n",        \
  41.                  __FILE__, __LINE__, yytext, yylineno);    \
  42. }
  43. #else
  44. #define DBPRINT
  45. #endif
  46. %}
  47. /* rule section --------------------------------------------------------------*/
  48. %%
  49. compound {            /* keyword compound */
  50.     DBPRINT;
  51.     return COMPOUND;
  52. }
  53. contains {            /* keyword contains */
  54.     DBPRINT;
  55.     return CONTAINS;
  56. }
  57. data[ \t\n]+file {        /* keyword data file */
  58.     DBPRINT;
  59.     return DATAFILE;
  60. }
  61. key {                /* keyword key */
  62.     DBPRINT;
  63.     return KEY;
  64. }
  65. index[ \t\n]+file {        /* keyword index file */
  66.     DBPRINT;
  67.     return INDEXFILE;
  68. }
  69. record {            /* keyword record */
  70.     DBPRINT;
  71.     return RECORD;
  72. }
  73. unique {            /* keyword unique */
  74.     DBPRINT;
  75.     return UNIQUE;
  76. }
  77. [ \t]+ {                /* blanks and tabs */
  78.     DBPRINT;
  79. }
  80. [A-Za-z][A-Za-z0-9_]* {            /* identifier */
  81.     DBPRINT;
  82.     /* copy identifier to yylval */
  83.     yylval.buf = (char *)malloc(yyleng + 1);
  84.     if (yylval.buf == NULL) {
  85.         perror("out of memory");
  86.         exit(EXIT_FAILURE);
  87.     }
  88.     strncpy(yylval.buf, yytext, yyleng);
  89.     yylval.buf[yyleng] = NUL;
  90.     return IDENTIFIER;
  91. }
  92. ^[ \t]*#.*$ {                /* C preprocessor statement */
  93.     DBPRINT;
  94.     fputs(yytext, hfp);
  95.     fputc('\n', hfp);
  96. }
  97. \" {                    /* string literal */
  98.     for (;;++yyleng) {
  99.         yytext[yyleng] = input();
  100.         if (yytext[yyleng] == '\n') {
  101.             yyerror("newline in string constant");
  102.             exit(EXIT_FAILURE);
  103.         }
  104.         if (feof(yyin)) {
  105.             yyerror("unexpected EOF in string constant");
  106.             exit(EXIT_FAILURE);
  107.         }
  108.         if (yytext[yyleng] == '\"' && yytext[yyleng - 1] != '\\') {
  109.             ++yyleng;
  110.             break;
  111.         }
  112.     }
  113.     yytext[yyleng] = NUL;
  114.     DBPRINT;
  115.     /* copy string to yylval w/o enclosing quotes */
  116.     yylval.buf = (char *)malloc(yyleng - 2 + 1);
  117.     if (yylval.buf == NULL) {
  118.         perror("out of memory");
  119.         exit(EXIT_FAILURE);
  120.     }
  121.     strncpy(yylval.buf, yytext + 1, yyleng - 2);
  122.     yylval.buf[yyleng - 2] = NUL; 
  123.     return STRING;
  124. }
  125. \[ {                    /* array element count */
  126.     for (;;++yyleng) {
  127.         yytext[yyleng] = input();
  128.         if (feof(yyin)) {
  129.             yyerror("unexpected EOF in string constant");
  130.             exit(EXIT_FAILURE);
  131.         }
  132.         if (yytext[yyleng] == ']') {
  133.             ++yyleng;
  134.             break;
  135.         }
  136.     }
  137.     yytext[yyleng] = NUL;
  138.     DBPRINT;
  139.     /* copy text to yylval w/o enclosing brackets */
  140.     yylval.buf = (char *)malloc(yyleng - 2 + 1);
  141.     if (yylval.buf == NULL) {
  142.         perror("out of memory");
  143.         exit(EXIT_FAILURE);
  144.     }
  145.     strncpy(yylval.buf, yytext + 1, yyleng - 2);
  146.     yylval.buf[yyleng - 2] = NUL;
  147.     return ELEMC;
  148. }
  149. "/*" {                    /* comment */
  150.     DBPRINT;
  151.     skipcomment();
  152. }
  153. . {                    /* single character delimiter */
  154.     DBPRINT;
  155.     return *yytext;
  156. }
  157. %%
  158.  
  159. /* subroutine section --------------------------------------------------------*/
  160. /* skipcomment:  skip C comment */
  161. #ifdef AC_PROTO
  162. int skipcomment(void) 
  163. #else
  164. int skipcomment() 
  165. #endif
  166. {
  167.     int    c    = 0;
  168.  
  169.     for (;;) {
  170.         while (!feof(yyin)) {
  171.             c = input();
  172.             if (c == '*') {
  173.                 break;
  174.             }
  175.         }
  176.         if (feof(yyin)) {
  177.             yyerror("unexpected EOF in comment");
  178.             exit(EXIT_FAILURE);
  179.         }
  180.         if (input() == '/') {
  181.             break;
  182.         } else {
  183.             unput(yytext[yyleng - 1]);
  184.         }
  185.     }
  186.  
  187.     return 0;
  188. }
  189.